import tensorflow as tf

x = tf.linspace(-10., 10., 21)

with tf.GradientTape() as tape:
    tape.watch(x)
    y = tf.sigmoid(x)

gradient = tape.gradient(y, [x])

print('x:\n', x)
print('sigmoid(x): \n', tf.sigmoid(x))
# 梯度从小（接近0）到大，然后从大到小（接近0）
print('gradient: \n{}'.format(gradient))

